$(function () {
    $("#topBtn").click(setTop);
    $("#wonderfulBtn").click(setWonderful);
    $("#deleteBtn").click(setDelete);
});

//点赞
function like(btn, entityType, entityId, entityUserId, discussPostId) {
    $.post(
        CONTEXT_PATH + '/like',
        {'entityType': entityType, 'entityId': entityId, "entityUserId":entityUserId, "discussPostId":discussPostId},
        function (data) {
            data = $.parseJSON(data);
            if (data.code == 0){
                $(btn).children("i").text(data.likeCount);//设置点赞数量
                $(btn).children("b").text(data.likeStatus==1?"已赞":"赞");//设置点赞状态
            }else {
                alert(data.msg);
            }
        }
    );
}

//置顶
function setTop() {
    $.post(
        CONTEXT_PATH + '/discusspost/top',
        {"id":$("#postId").val()},
        function (data) {
            data = $.parseJSON(data);

            if (data.code == 0){
                $("#topBtn").attr('disabled', 'disabled');
            }else {
                alert(data.msg);
            }
        }
    );
}

//加精
function setWonderful() {
    $.post(
        CONTEXT_PATH + '/discusspost/wonderful',
        {"id":$("#postId").val()},
        function (data) {
            data = $.parseJSON(data);

            if (data.code == 0){
                $("#wonderfulBtn").attr('disabled', 'disabled');
            }else {
                alert(data.msg);
            }
        }
    );
}

//删除
function setDelete() {
    $.post(
        CONTEXT_PATH + '/discusspost/delete',
        {"id":$("#postId").val()},
        function (data) {
            data = $.parseJSON(data);

            if (data.code == 0){
                location.href = CONTEXT_PATH + '/index';
            }else {
                alert(data.msg);
            }
        }
    );
}